package com.zc.web.controller.timedown;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zc.common.utils.poi.ExcelUtil;
import com.zc.web.domain.TimeRecord;
import com.zc.web.service.ITimeRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zc.common.annotation.Log;
import com.zc.common.core.controller.BaseController;
import com.zc.common.core.domain.AjaxResult;
import com.zc.common.enums.BusinessType;

import com.zc.common.core.page.TableDataInfo;

/**
 * 时间账本Controller
 * 
 * @author zc
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/wx/record")
public class TimeRecordController extends BaseController
{
    @Autowired
    private ITimeRecordService timeRecordService;

    /**
     * 查询时间账本列表
     */
    @PreAuthorize("@ss.hasPermi('wx:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(TimeRecord timeRecord)
    {
        startPage();
        List<TimeRecord> list = timeRecordService.selectTimeRecordList(timeRecord);
        return getDataTable(list);
    }

    /**
     * 导出时间账本列表
     */
    @PreAuthorize("@ss.hasPermi('wx:record:export')")
    @Log(title = "时间账本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TimeRecord timeRecord)
    {
        List<TimeRecord> list = timeRecordService.selectTimeRecordList(timeRecord);
        ExcelUtil<TimeRecord> util = new ExcelUtil<TimeRecord>(TimeRecord.class);
        util.exportExcel(response, list, "时间账本数据");
    }

    /**
     * 获取时间账本详细信息
     */
    @PreAuthorize("@ss.hasPermi('wx:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(timeRecordService.selectTimeRecordById(id));
    }

    /**
     * 新增时间账本
     */
    @PreAuthorize("@ss.hasPermi('wx:record:add')")
    @Log(title = "时间账本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TimeRecord timeRecord)
    {
        return toAjax(timeRecordService.insertTimeRecord(timeRecord));
    }

    /**
     * 修改时间账本
     */
    @PreAuthorize("@ss.hasPermi('wx:record:edit')")
    @Log(title = "时间账本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TimeRecord timeRecord)
    {
        return toAjax(timeRecordService.updateTimeRecord(timeRecord));
    }

    /**
     * 删除时间账本
     */
    @PreAuthorize("@ss.hasPermi('wx:record:remove')")
    @Log(title = "时间账本", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(timeRecordService.deleteTimeRecordByIds(ids));
    }
}
